<?php
namespace app\yunda\home;

use app\yunda\model\Postage as PostageModel;

/**
 * Class China运费查询
 * @package app\yunda\home
 */
class Postage extends Base {
//    // 获取列表
    public function index(){
        //接收查询数据
        $body=request()->only(['sp','sc','sa','gp','gc','ga','weight','long','wide','high']);
        //验证数据
        $result=$this->validate($body,'Fee');
        if($result!==true) return mogo_error($result,404);
        //韵达运费按省份计算
        //查询数据
        $map=[
            'sp'=>$body['sp'],
            'gp'=>$body['gp'],
        ];
        //halt($body);
        $Post = new PostageModel();
        $row =  $Post->where($map)->find();
        if(empty($row)) return  mogo_json($row,'暂无数据',0);
        if($body['weight']<=$row['head_weight']){
            $fee=$row['hw_money'];
        }else{
            //首重金额+超过续重*续重金额
          $fee=$row['hw_money']+($body['weight']-$row['head_weight'])*$row['ow_money'];
        }
        if(!isset($body['long']) || !isset($body['wide']) || !isset($body['high'])){
            $body['long']=0;
            $body['wide']=0;
            $body['high']=0;
        }
        //存在轻抛货物
        if(is_numeric($body['long']) && is_numeric($body['wide']) && is_numeric($body['high'])){
            $fee+=($body['long']*$body['wide']*$body['high'])/60000;
            $fee=ceil($fee);//向上取整
        }
        return mogo_json($fee,'ok',1);
    }



}